package com.jacquesh;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 比如上游有2个partition
 * 下游有4个partition
 * 那么rescale 会先进行计算  会尽量把当前分区的数据 分配给当前分区的subtask
 * 这样的话 尽可能的减少了网络传输
 */
public class FlinkDemo0015 {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment =
                StreamExecutionEnvironment.getExecutionEnvironment();
        /**设置默认并行度为4*/
        environment.setParallelism(4);
        /**获取随机数流 ： 1~10*/
        DataStreamSource<Long> stream = environment.generateSequence(1,10)
                /**并行度设置为1*/
                .setParallelism(2);
        stream.rescale().print();
        environment.execute("rescale");
    }
}
